#include "RawSocket.h"
#include <fcntl.h>

int create_icmp_socket()
{
    struct protoent *proto = getprotobyname("icmp");//根据name获取协议编号
    int sock = -1;
    if ((sock=socket(AF_INET, SOCK_RAW, (proto ? proto->p_proto :1))) < 0)
    // if ((sock=socket(PF_PACKET, SOCK_RAW, htons(P_ALL))) < 0)
    {
        perror("create sock error");
        return sock;
    }
    int flag = fcntl(sock, F_GETFL);
    fcntl(sock, flag|O_NONBLOCK);
    return sock;
}